package smetana.modules.ui.actions;

import com.google.inject.Inject;
import smetana.modules.ui.form.doc.DocEditPanel;
import smetana.modules.ui.form.doc.DocListPanel;
import smetana.modules.ui.form.window.ToolbarPanel;
import smetana.modules.ui.form.window.WorkPanel;
import smetana.modules.ui.model.UIModel;

/**
 *
 * @author dmitry.mamonov
 */
public class SaveDocumentAction extends AbstractAction {
    @Inject
    ToolbarPanel toolbarPanel;

    @Inject
    WorkPanel workPanel;

    @Inject
    DocEditPanel docEditPanel;

    @Inject
    DocListPanel docListPanel;

    @Inject
    UIModel uiModel;

    @Override
    public void perform() {
        //actions and toolbar
        this.actionDelete.setEnabled(true);
        this.actionCreate.setEnabled(true);
        toolbarPanel.getButtonEdit().setVisible(true);
        toolbarPanel.getButtonSave().setVisible(false);

        //edit panel
        docEditPanel.store();

        //list panel
        docListPanel.refresh(); //TODO
        docListPanel.selectDocumentReport(uiModel.getCursorDoc().get());

        //work panel
        workPanel.switchToDocumentsList();
    }
}
